﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SystemControllers;
using eTMS.Controllers;
using eTMS.Commons;
using SystemControllers.RolesService;

namespace eTMS.Forms.Systems{
    public partial class FrmAddNewRoles: eTMS.Controls.BaseForm
    {
        public FrmAddNewRoles()
        {
            InitializeComponent();
        }
        #region Variables
        private RolesController controller=new RolesController();
        #endregion
        #region Screen Functions
        //Load All lable text
        private void LoadLanguage(){			
			this.Text=Constants.APP_ADDNEW+" "+RolesStringMapping.Roles;
			this.labelFormTitle.Text=Constants.APP_ADDNEW+" "+RolesStringMapping.Roles;
			labelRoleCode.Text=RolesStringMapping.RoleCode;			
			labelRoleName.Text=RolesStringMapping.RoleName;			
			labelRoleDescription.Text=RolesStringMapping.RoleDescription;			
			labelRoleType.Text=RolesStringMapping.RoleType;			
        }
        //Copy data from control in screen to object
        private void CopyFromSreen(RolesEntity o){
			 o.RoleCode=Convert.ToString(txtRoleCode.Text);
			 o.RoleName=Convert.ToString(txtRoleName.Text);
			 o.RoleDescription=Convert.ToString(txtRoleDescription.Text);
			 o.RoleType=(byte)txtRoleType.Value;
        }
        //Validate all data from control in screen before Save data
        protected bool ValidateScreen(){
		    bool result=true;
		    if(!result){
				ShowInfo(Constants.MSS_REQUIRE_FIELD);
		    }
		    return result;
        }
        #endregion
        #region Business
        //AddNew data to database
        private bool AddNewData()
        {
            controller.ResetObject();	
		    CopyFromSreen(controller.RolesObject);		    
            bool rval=controller.AddNew();
            return rval;
        }
        #endregion
        #region Windows Control EventHandlers
        private void FrmAddNewRoles_Load(object sender, EventArgs e)
        {
			LoadLanguage();
        }       
        private void ucCommand_OnOK(object sender, CancelEventArgs args)
        {
			if(!ValidateScreen()){
				args.Cancel = true;
				return;
			}            
            if(AddNewData()){
                ShowInfo(Constants.MSS_SAVE_SUCCESS);
            }
            else{
				args.Cancel = true;
                ShowWarning(Constants.MSS_SAVE_FAILE);
            }
        }
        private void ucCommand_OnCancel(object sender, CancelEventArgs args)
        {
        }
        #endregion
    }
}
